import Vue from "vue";
import App from "./App.vue";
import router from "./router";
import store from "./store";

//引入RTCMS SDK
import tvvssdk from "../public/js/sdk/tvvssdk.js";
Vue.prototype.$tvvssdk = tvvssdk;

// 导入VIEW UI
import ViewUI from "view-design";
import "view-design/dist/styles/iview.css";
Vue.use(ViewUI);

// 导入ElementUI
import ElementUI, { Message } from "element-ui";
import "element-ui/lib/theme-chalk/index.css";

// ...

// 为了实现Class的私有属性
const showMessage = Symbol("showMessage");
/**
 *  重写ElementUI的Message
 *  single默认值true，因为项目需求，默认只弹出一个，可以根据实际需要设置
 */
class DonMessage {
  success(options, single = true) {
    this[showMessage]("success", options, single);
  }
  warning(options, single = true) {
    this[showMessage]("warning", options, single);
  }
  info(options, single = true) {
    this[showMessage]("info", options, single);
  }
  error(options, single = true) {
    this[showMessage]("error", options, single);
  }

  [showMessage](type, options, single) {
    if (single) {
      // 判断是否已存在Message
      if (document.getElementsByClassName("el-message").length === 0) {
        Message[type](options);
      }
    } else {
      Message[type](options);
    }
  }
}
Vue.use(ElementUI);
Vue.prototype.$message = new DonMessage();
// 引入定制化的axios
import axios from "./axios";
Vue.prototype.axios = axios;

// 引入Vue-cookies
import VueCookies from "vue-cookies";
Vue.use(VueCookies);

/**
 * md5加密方法  不要修改
 * 用法：  this.$getMD5(str)
 * @param str
 * @returns {*}
 */
import crypto from "crypto";
Vue.prototype.$getMD5 = function(str) {
  const md5 = crypto.createHash("md5");
  md5.update(str);
  return md5.digest("hex");
};

import moment from "moment";
/**
 * 全局date格式化过滤器  不要修改
 * 用法 {{ scope.row.createTime | date('YYYY-MM-DD HH:mm:ss') }}
 */
Vue.filter("date", function(value, format) {
  if (!value) return "";
  if (!format) return value;

  value = parseInt(value);
  return moment(value).format(format);
});

/**
 * 格式化工具
 * 用法：  this.$dateFormat(date, format);
 * @param date
 * @param format
 * @returns {*}
 */
Vue.prototype.$dateFormat = function(date, format) {
  if (!date) return "";
  if (!format) return date;
  return moment(date).format(format);
};
Vue.prototype.$secondsFormat = function(times) {
  var t;
  if (times > -1) {
    var hour = Math.floor(times / 3600);
    var min = Math.floor(times / 60) % 60;
    var sec = times % 60;
    if (hour < 10) {
      t = "0" + hour + ":";
    } else {
      t = hour + ":";
    }

    if (min < 10) {
      t += "0";
    }
    t += min + ":";
    if (sec < 10) {
      t += "0";
    }
    t += sec.toFixed(2);
  }
  t = t.substring(0, t.length - 3);
  return t;
};
Vue.config.productionTip = false;
let url = "wss://meeting.zwan.com.cn:2237/websocket"; //演示地址
Vue.prototype.$BashUrl = url;

new Vue({
  router,
  store,
  render: h => h(App)
}).$mount("#app");
